package com.ruoyi.system.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import org.springframework.stereotype.Component;


import java.util.HashMap;

@Component
public class MapConverter implements Converter<HashMap> {

    @Override
    public Class<HashMap> supportJavaTypeKey() {
        return HashMap.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public HashMap convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return (HashMap) new HashMap().put(cellData.getStringValue(),cellData.getStringValue());
    }

    @Override
    public CellData convertToExcelData(HashMap value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return new CellData(value);
    }
}
